package domain

import (
	"album/dao"
	"album/repo"
	"context"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
	"listenboos-common/db"
)

type AlbumStatDomain struct {
	albumStatRepo repo.AlbumStatRepo1
}

func (u *AlbumStatDomain) FindByAlbumId(ctx context.Context, id int64) (playStatNum, subscribeStatNum, buyStatNum, commentStatNum string, err error) {
	playStatNum, subscribeStatNum, buyStatNum, commentStatNum, err = u.albumStatRepo.FindByAlbumId(ctx, id)
	if err != nil {
		logx.Error(err)
		return "", "", "", "", errors.New("数据库异常")
	}
	return playStatNum, subscribeStatNum, buyStatNum, commentStatNum, err
}
func (u *AlbumStatDomain) SaveAlbumStat(ctx context.Context, conn db.DBConn, id int64) error {
	err := u.albumStatRepo.Save(ctx, conn, id)
	if err != nil {
		logx.Error(err)
		return errors.New("数据库异常")
	}
	return nil
}
func NewAlbumStatDomain(db *db.ListenDB) *AlbumStatDomain {
	return &AlbumStatDomain{
		albumStatRepo: dao.NewAlbumStatDao(db),
	}
}
